//
//  PublicGoodController.m
//  LiquorChain
//
//  Created by apple on 2019/1/5.
//  Copyright © 2019年 王冬. All rights reserved.
//

#import "PublicGoodController.h"
#import "PubgoodCell.h"
@interface PublicGoodController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation PublicGoodController
static NSString *CellIdentifier = @"pubgoodCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"公益池";

    self.view.backgroundColor =[UIColor whiteColor];
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, kNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT - kNavBarHeight- kIPhoneXBottomHeight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    // [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"PubgoodCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
    
    [self creatHeadView];
    // Do any additional setup after loading the view.
}

-(void)creatHeadView{
    UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220)];
    headView.backgroundColor =[UIColor whiteColor];
    UIView *topView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
    topView.backgroundColor = RGBA(16.0, 0.0, 52.0, 1);
    UILabel *showLabel =[[UILabel alloc]init];
    [topView addSubview:showLabel];
    showLabel.text = @"公益总量(滴)";
    showLabel.textColor = [UIColor whiteColor];
    showLabel.font =[UIFont systemFontOfSize:12];
    [showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(21);
        make.left.mas_equalTo(14);
        make.height.mas_equalTo(12);
    }];
    //
    UILabel *showNumber =[[UILabel alloc]init];
    [topView addSubview:showNumber];
    showNumber.textColor =[UIColor whiteColor];
    showNumber.text =@"0.00001";
    showNumber.font = [UIFont systemFontOfSize:30];
    [showNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.top.mas_equalTo(40);
        make.height.mas_equalTo(23);
    }];
//    // 昨日圣酒
//    UILabel *oldLabel =[[UILabel alloc]init];
//    [topView addSubview:oldLabel];
//    oldLabel.textColor = [UIColor whiteColor];
//    oldLabel.font = [UIFont systemFontOfSize:12];
//    oldLabel.text = [NSString stringWithFormat:@"昨日:%f",0.12];
//    [oldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left .mas_equalTo(14);
//        make.top.mas_equalTo(71);
//        make.height.mas_equalTo(12);
//    }];
    UILabel *infoLabel =[[UILabel alloc]init];
    [topView addSubview:infoLabel];
    infoLabel.textColor =[UIColor whiteColor];
    infoLabel.font =[UIFont systemFontOfSize:12];
    infoLabel.text = @"酒链世界“圣酒公益池”简称公益池，公益池所有圣酒将作为酒链公益事业储备。";
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:infoLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    [paragraphStyle setLineSpacing:10];//调整行间距
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [infoLabel.text length])];
    infoLabel.attributedText = attributedString;
    [infoLabel sizeToFit];
    
    
    infoLabel.numberOfLines = 0;
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.right.mas_equalTo(-14);
        make.top.mas_equalTo(110);
    }];
    
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [topView addSubview:rightBtn];
    [rightBtn setBackgroundColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.3]];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40);
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(30);
    }];
    rightBtn.layer.cornerRadius = 15;
    [rightBtn setTitle:@"公益池来源" forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"rightj"] forState:UIControlStateNormal];
    [rightBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:4];
    [rightBtn setTitleColor:[UIColor whiteColor]
                   forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:topView];
    
   // 爱心记录
        UILabel *pubGLabel =[[UILabel alloc]init];
        [headView addSubview:pubGLabel];
        pubGLabel.font = [UIFont systemFontOfSize:15];
        pubGLabel.text = @"爱心记录";
        [pubGLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left .mas_equalTo(15);
            make.top.mas_equalTo(topView.mas_bottom).with.offset(30);
            make.height.mas_equalTo(15);
        }];
    
    UILabel *pubGLabline =[[UILabel alloc]init];
    [headView addSubview:pubGLabline];
    pubGLabline.backgroundColor =[UIColor blackColor];
    [pubGLabline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left .mas_equalTo(15);
        make.top.mas_equalTo(pubGLabel.mas_bottom).with.offset(15);
        make.height.mas_equalTo(2);
        make.width.mas_equalTo(30);
    }];
    self.tableView.tableHeaderView = headView;
}

-(void)rightClick:(UIButton *)sender{
    NSLog(@"公益池来源");
    //创建控制器
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"公益池来源" message:
                                  @"                                                                   1、酿酒师领取的每滴圣酒，其中3%作为谢师酒，贡献给推荐人，若无推荐人则流入公益池；\n2、推荐人超过48小时不储存停止酿酒情况，粉丝的谢师酒，直接流入公益池；\n3、新用户注册不常见数字钱包，只有5天体验期，注册当日就算一天， 满5天后酿酒机停止酿酒，体验期内正常领酒，其谢师酒直接流入公益池；\n4、长久后的12个小时内为品酒时间，超过时间后，为品尝的圣酒流入公益池。                                                        " preferredStyle:UIAlertControllerStyleAlert];
    //创建添加按钮（可以写事件，也可以不写），可以创建多个按钮
    UIAlertAction *OKbtn = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];

    //修改message
    //设置行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.alignment = NSTextAlignmentLeft;
    paragraphStyle.lineSpacing = 10;//行间距
    
    
    NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSParagraphStyleAttributeName:paragraphStyle};//字体大小 行间距  颜色
    
    
    [alertVC setValue: [[NSAttributedString alloc]initWithString:alertVC.message attributes:attributes] forKey:@"attributedMessage"];


    //backImage
    UIImage *accessoryImage = [UIImage imageNamed:@"backImage1"];
    
    accessoryImage = [accessoryImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [OKbtn setValue:accessoryImage forKey:@"image"];
    
    [OKbtn setValue:[UIColor whiteColor] forKey:@"_titleTextColor"];
    
    
    //添加按钮到alertVC上，并模态出来
    [alertVC addAction:OKbtn];
    [self presentViewController:alertVC animated:YES completion:nil];
    
}

#pragma mark
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PubgoodCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld",indexPath.row);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
